// ==UserScript==
// @name         gfycat direct
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Redirects gfycat pages to direct video urls
// @author       boiledpotato23
// @homepage     https://notabug.org/boiledpotato23/gfycat-resurrected/
// @downloadURL  https://notabug.org/boiledpotato23/gfycat-resurrected/raw/master/gfycat-direct.user.js
// @updateURL    https://notabug.org/boiledpotato23/gfycat-resurrected/raw/master/gfycat-direct.user.js
// @match        https://web.archive.org/web/*
// @icon         https://notabug.org/boiledpotato23/boiledpotato23/raw/cffea1f19170e2ca4836f5b508843e49607650f6/avatar.png
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function replaceVideoSrcs() {
        const videoSrcs = document.querySelectorAll('source[src*="https://web.archive.org/web/"]');
        if(videoSrcs.length === 1) return;

        const directUrl = "https://web.archive.org/web/1if_/" + videoSrcs[0].src;

        window.location = directUrl;
    }

    if(document.readyState == "interactive") {
        replaceVideoSrcs();
    }
})();